package com.turing.manage.email.listener;

import java.util.Timer;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

/**
 * @desc   上下文内容监听器，目的是为了配合定时邮件发送任务类实现生日祝福
 * @author wyh
 * @time   2022-01-07
 */
public class MyContextListener   implements ServletContextListener{
	//1.声明一个Timer定时器
	private Timer timer = null;
	
	@Override
	public void contextInitialized(ServletContextEvent sce) {
		System.out.println("contextInitialized()---项目启动的时候触发");
		timer=new Timer();
		timer.schedule(new EmailTask(), 1000, 3000);
	}

	@Override
	public void contextDestroyed(ServletContextEvent sce) {
		System.out.println("contextDestroyed()---项目结束的时候触发");
        timer.cancel();
        System.out.println("定时器取消了.......");
	}

}
